package com.utils.info.util.hhy;

public class RouteUtil {

    /**
     *
     * @param value 值
     * @param length 取模长度，对该值取模后会得到0到length的值
     * @return
     */
    public static int getRoutingIndex(String value,int length) {
        String key = String.valueOf(value);
        int h;
        int hash = (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
        int index = length & hash;
        return index;
    }


    /**
     *
     * @param value 值
     * @param length 取模长度，对该值取模后会得到0到length的值
     * @return
     */
    public static int getRoutingIndex(long value,int length) {
        int index = (int) (value%length);
        return index;
    }
}
